package com.qiandw.spark.sql

import com.qiandw.spark.{SparkContextFactory, SparkSqlSrv}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cache.annotation.{CacheConfig, Cacheable}
import org.springframework.stereotype.Component

@Component
class DemoSrvImpl extends DemoSrv {

  @Autowired
  var scf: SparkContextFactory = _

  @Autowired
  var srv: SparkSqlSrv = _

  override def demo(): Unit = {

    srv.sql("select qdw_id from member")._2
      .foreach(x=>{
        println(x)
      })

  }
  override def demo1(): Unit = {

    scf.getSparkSession.sql("select qdw_id from member").rdd.collect()
      .foreach(x=>{
        println(x)
      })

  }

  override def demo2(): Unit = {
    scf.getSparkSession.sql("select name from t_member").rdd.collect()
      .foreach(x=>{
        println(x)
      })
  }


  @Cacheable(cacheNames = Array("demo3"))
  override def demo3(): String = {
    println("run")
    "132"
  }

}
